

use "$data/survey1_clean.dta", clear


global control male age_* log_inc log_inc_sq highschool college working student democrat republican 

replace perceived_mortality=65 if perceived_mortality>65 // Winsorize manually
replace perceived_mortality=perceived_mortality/100

sum perceived_contagion , d
replace perceived_contagion =r(p95) if perceived_contagion>r(p95)
replace perceived_contagion=perceived_contagion/100


*** Correlation with continuous perceptions ***

loc experiments "z_impact_1 z_impact_2 z_worry_corona_econ z_worry_perecon"
		   			  
			  
preserve 

clear all
eststo clear
estimates drop _all

set obs 10
qui gen x = 1
qui gen y = 1

loc columns = 0

foreach choice in `experiments' {

    loc ++columns
    qui eststo col`columns': reg x y

}

restore


/* Statistics */

loc colnum = 1
loc colnames ""

global output_coeff ""
global output_se ""
global output_name""

foreach choice in `experiments' {

/* Statistics */

	
 xi:  reg `choice' perceived_mortality  perceived_contagion , vce(r)
 	

	estadd loc thisstat9 = string(`e(r2)', "%9.2f"): col`colnum'
 
    sigstar perceived_mortality, prec(4)
    estadd loc thisstat3 = "`r(bstar)'": col`colnum'
    estadd loc thisstat4 = "`r(sestar)'": col`colnum'
	
	
    sigstar perceived_contagion, prec(4)
    estadd loc thisstat6 = "`r(bstar)'": col`colnum'
    estadd loc thisstat7 = "`r(sestar)'": col`colnum'			

	

	** With controls **
	
 xi:  reg `choice' perceived_mortality  perceived_contagion $control, vce(r)
 	
	estadd loc thisstat20 = string(`e(r2)', "%9.2f"): col`colnum'
 
    sigstar perceived_mortality, prec(4)
    estadd loc thisstat14 = "`r(bstar)'": col`colnum'
    estadd loc thisstat15 = "`r(sestar)'": col`colnum'
	
	lincom perceived_mortality

    sigstar perceived_contagion, prec(4)
    estadd loc thisstat17 = "`r(bstar)'": col`colnum'
    estadd loc thisstat18 = "`r(sestar)'": col`colnum'			

	qui sum `choice'  
	estadd loc thisstat21 =  r(N): col`colnum'
	
    loc ++colnum
    loc colnames "`colnames' `"`: var la `choice''"'"

	} 
	

loc rowlabels " "{\bf Panel A: No control variables}"  " " "Perceived mortality" " "  " " "Perceived contagiousness " " " " " "\midrule R$^2$" "\midrule" " " "{\bf Panel B: Including control variables}"  " " "Perceived mortality" " "  " " "Perceived contagiousness" " " " "  "\midrule R$^2$" " Number of Observations ""
loc rowstats ""

forval i = 1/21 {
    loc rowstats "`rowstats' thisstat`i'"
}

	
esttab * using "$tables/experiment_correlations_combined_continuous.tex", replace cells(none) booktabs nonotes compress alignment(c) nogap noobs nobaselevels label stats(`rowstats', labels(`rowlabels')) ///
 mtitle("World" "US" "US Economy" "Pers. Economic Sit."  ) ///
mgroups("Predicted impact on (standardized)" "Worry about (standardized)" ,  pattern(1 0  1 0   ) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}))
